package com.news.ui.main.fragment;

import android.widget.ListView;
import android.widget.Toast;

import com.news.R;
import com.news.base.BaseMvpFragment;
import com.news.model.bean.Joke;
import com.news.presenter.JokePresenter;
import com.news.presenter.contract.JokeContract;
import com.news.ui.main.adapter.JokeAdapter;

import java.util.ArrayList;

import javax.inject.Inject;

import butterknife.BindView;

/**
 * Created with Android Studio
 * User: ShiLiang
 * Date: 2017/3/2/0002
 * Project: TodayNews
 */

public class JokeFragment extends BaseMvpFragment<JokePresenter> implements JokeContract.View{

    @BindView(R.id.joke_list)
    ListView mListView;
    @Inject
    JokeAdapter mJokeAdapter;

    @Override
    public int getLayoutId() {
        setHasProgress(true);
        return R.layout.fragment_joke;
    }

    @Override
    public void initViews() {
        mListView.setAdapter(mJokeAdapter);
    }

    @Override
    public void loadData() {
        mPresenter.fetchJokes();
    }

    @Override
    protected void initInject() {
        getFragmentComponent().inject(this);
    }

    @Override
    public void showJokes(ArrayList<Joke> jokes) {
        mJokeAdapter.add(jokes);
    }

    @Override
    public void showError(String error) {
        Toast.makeText(mContext, "error", Toast.LENGTH_SHORT).show();
    }
}
